package com.ycrlkj.android.modulespublic.common.net.exception;

import android.app.Activity;
import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.ycrlkj.android.modulespublic.common.utils.xpopup.XPopupUtil;

public class ApiExceptionHandler {

    public static void doWith(Activity activity, ApiException apiException) {

        doWith(activity, apiException, null, null);

    }

    public static void doWith(Activity activity, ApiException apiException, OnConfirmListener confirmCallBack, OnCancelListener cancelCallBack) {

        Integer code = apiException.getCode();
        String message = apiException.getMessage();

        if (code >= 7000) {

            ToastUtils.showLong(message);

        } else if (code >= 6000) {

            ToastUtils.showLong(message);

        } else if (code == 5000) {

            ToastUtils.showLong(message);

        } else if (code == 4040) {

            ToastUtils.showLong(message);

        } else if (code == 4014) {

            ToastUtils.showLong(message);

        } else if (code == 4013) {

            ToastUtils.showLong(message);

        } else if (code == 4012) {

            ToastUtils.showLong(message);

        } else if (code == 4011) {

            ToastUtils.showLong(message);

        } else if (code == 4010) {

            XPopupUtil.showAlert(activity, message);

        } else if (code == 4002) {

            XPopupUtil.showModal(activity, message, confirmCallBack, cancelCallBack);

        } else if (code == 4001) {

            XPopupUtil.showAlert(activity, message);

        } else if (code == 4000) {

            ToastUtils.showLong(message);

        }
    }

}
